package com.blb.ishop.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * IOC容器工具
 */
@ComponentScan(basePackages = "com.blb.ishop")
@Configuration
//允许自动生成代理对象
@EnableAspectJAutoProxy
public class ApplicationContextUtil {

    //容器对象
    private static ApplicationContext applicationContext;

    static{
        applicationContext = new AnnotationConfigApplicationContext(ApplicationContextUtil.class);
//        applicationContext = new ClassPathXmlApplicationContext("spring.xml");
    }

    /**
     * 获得容器中的对象
     * @param clazz
     * @return
     */
    public static Object getBean(Class clazz){
        return applicationContext.getBean(clazz);
    }
}
